package cn.silver.module.configuration.bean;

import cn.silver.framework.core.model.DictModel;
import cn.silver.framework.excel.convert.ExcelDictConvert;
import cn.silver.framework.mybatis.bean.BusBean;
import cn.silver.module.configuration.domain.SysDictItem;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;


/**
 * 字典数据视图对象 sys_dict_data
 *
 * @author Silver Zhou
 */
@Data
@NoArgsConstructor
@ExcelIgnoreUnannotated
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = SysDictItem.class)
@Schema(name = "DictItemBean", title = "字典配置信息对象")
public class DictItemBean extends BusBean implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 字典类型
     */
    @Schema(title = "字典类型")
    @ExcelProperty(value = "字典类型")
    private String type;

    /**
     * 字典排序
     */
    @Schema(title = "字典排序")
    @ExcelProperty(value = "字典排序")
    private Integer sort;

    /**
     * 是否默认（Y是 N否）
     */
    @Schema(title = "是否默认")
    @ExcelProperty(value = "是否默认", converter = ExcelDictConvert.class)
    private Boolean defaulted;

    /**
     * 样式属性（其他样式扩展）
     */
    @Schema(title = "样式属性")
    private String cssClass;

    /**
     * 表格回显样式
     */
    @Schema(title = "表格回显样式")
    private String listClass;

    public DictModel convertModel() {
        DictModel dictModel = new DictModel(this.getId(), this.getName(), this.getCode(), this.type, this.sort, this.getRemark());
        dictModel.setCssClass(getCssClass());
        dictModel.setListClass(getListClass());
        return dictModel;
    }
}
